package main

import (
	//"github.com/rtp"
	//"github.com/rtp"
	"log"
	"net"
	"strconv"
	"time"
)

func UdpTest()  {
	for i:= 0;i< 10;i++{
		sended := 0
		cnn,e := net.Dial("udp","127.0.0.1:861")
		if nil != e{
			log.Print(e.Error())
		}
		for sended < len("hello world"){
			n,e := cnn.Write([]byte("hello world"))
			if nil != e{
				log.Print(e.Error())
			}
			sended += n
		}

	}
}

func main()  {
	index, e := net.InterfaceByIndex(1)
	log.Print(index)
	if nil != e{
		log.Print(e.Error())
	}
	ua,e := net.ResolveUDPAddr("udp","127.0.0.1:861")
	if nil != e{
		log.Print(e.Error())
	}
	conn,e := net.ListenUDP("udp",ua)
	if nil != e{
		log.Print(e.Error())
	}
	go UdpTest()
	for true {
		if nil == conn{
			return
		}
		time.Sleep(time.Millisecond)
		b := make([]byte, 1024)
		n, e := conn.Read(b)
		if nil != e {
			log.Print(e.Error())
		}
		log.Print("recv "+ strconv.Itoa(n) + " data: ",string(b[0:n]))
	}
	/*
	trans := rtp.NewTransport("udp",index,ua,false)
	session := rtp.NewSession(trans,trans,rtp.SessionParam{})
	e = session.Run()
	if nil != e{
		log.Print(e.Error())
	}*/
}
